#include <cstdio>
#include <algorithm>
#include <cstring>
const int MAXN=150;
struct B{
    int p;
    int m;
};
B b[MAXN];
int v,n;
using namespace std;
bool cmp(B a,B b){
    return a.p>b.p;
}
int main(void){
    while(~scanf("%d",&v)){
        if(v==0){
            break;
        }
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d%d",&b[i].p,&b[i].m);
        }
        int ans=0;
        sort(b,b+n,cmp);
        for(int i=0;i<n;i++){
            if(v>=b[i].m){
                v-=b[i].m;
                ans+=b[i].p*b[i].m;
            }
            else{
                ans+=b[i].p*v;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
